package com.video.controller;

import com.video.bean.UserInfo;
import com.video.service.UserServiceI;
import com.video.utils.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

    @Autowired
    private UserServiceI userServiceI;

    @RequestMapping("/register")
    public String register(UserInfo userInfo,HttpServletRequest req) {
        userServiceI.register(userInfo,req);
        return "login";
    }

    @RequestMapping("/login")
    @ResponseBody
    public ResultMap login(String username, String password, HttpServletRequest request) {
        return userServiceI.login(username,password,request);
    }

    @RequestMapping("/selectAllUser")
    @ResponseBody
    public ResultMap selectAllUser(int page, int limit) {
        return userServiceI.selectAllUser(page,limit);
    }

    @RequestMapping("/updateUserInfoByUsername")
    public String updateUserInfoByUsername(UserInfo userInfo, HttpServletRequest request) {
        userServiceI.updateUserInfoByUsername(userInfo,request);
        return "login";
    }

}
